import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:kkhousekeep/page/me/house_authentication_detail_controller.dart';
import 'package:kkhousekeep/widget/shadow_widget.dart';

import '../../widget/custom_app_bar.dart';

class HouseAuthenticationDetailPage extends StatelessWidget {
  const HouseAuthenticationDetailPage({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<HouseAuthenticationDetailController>(
        init: HouseAuthenticationDetailController(),
        builder: (controller) => Scaffold(
            backgroundColor: const Color(0xFFf4f5f6),
            appBar: CustomAppBar("房屋认证详情"),
            body: SafeArea(
              left: false,
              right: false,
              child: ShadowWidget.fixedHeight(
                radius: 24,
                paddingVertical: 40,
                paddingHorizontal: 48,
                marginHorizontal: 32,
                marginVertical: 32,
                height: 1080,
                backgroundColor: Colors.white,
                child: Obx(
                  () => Column(
                    children: [
                      Text(
                        controller.status.value,
                        style: TextStyle(
                            fontSize: 36.sp,
                            color: const Color(0xFF0B0D0f),
                            fontWeight: FontWeight.w500),
                      ).marginOnly(bottom: 8.h),
                      Text(controller.time.value,
                              style: TextStyle(
                                  fontSize: 24.sp,
                                  color: const Color(0xFFC6C9CC)))
                          .marginOnly(bottom: 44.h),
                      _buildDetail(controller),
                      Container(
                        alignment: Alignment.centerLeft,
                        padding: EdgeInsets.only(top: 16.h, bottom: 32.h),
                        child: Container(
                            alignment: Alignment.centerLeft,
                            width: 180.w,
                            height: 252.h,
                            decoration: BoxDecoration(
                              border: Border.all(
                                  color: const Color(0x33000000), width: 2.r),
                              borderRadius: BorderRadius.circular(12.r),
                              image: DecorationImage(
                                  fit: BoxFit.fill,
                                  image: NetworkImage(controller.image.value)),
                            )),
                      ),
                      Visibility(
                          visible:
                              controller.isShowApplicationTimeInBottom.value,
                          child: Align(
                            alignment: Alignment.centerLeft,
                            child: Text(
                              controller.applicationTime.value,
                              style: TextStyle(
                                fontSize: 24.sp,
                                color: const Color(0xFFC6C9CC),
                              ),
                            ),
                          )),
                    ],
                  ),
                ),
              ),
            )));
  }

  Widget _buildDetail(HouseAuthenticationDetailController controller) {
    return Table(
      defaultVerticalAlignment: TableCellVerticalAlignment.middle,
      columnWidths: const {
        0: IntrinsicColumnWidth(),
        1: FlexColumnWidth(),
      },
      children: [
        TableRow(children: [
          buildFormTitle("业主姓名"),
          buildFormContent(controller.name.value),
        ]),
        TableRow(children: [
          buildFormTitle("电话"),
          buildFormContent(controller.phone.value),
        ]),
        TableRow(children: [
          buildFormTitle("证件类型"),
          buildFormContent(controller.idCardType.value),
        ]),
        TableRow(children: [
          buildFormTitle("证件号码"),
          buildFormContent(controller.idCarNumber.value),
        ]),
        TableRow(children: [
          buildFormTitle("入户日期"),
          buildFormContent(controller.enterTime.value),
        ]),
        TableRow(children: [
          buildFormTitle("个人照片"),
          Container(),
        ])
      ],
    );
  }

  buildFormTitle(String title) {
    return Padding(
      padding: EdgeInsets.only(top: 16.h, bottom: 16.h),
      child: Text(
        title,
        style: TextStyle(fontSize: 32.sp, color: const Color(0xFF999999)),
      ),
    );
  }

  buildFormContent(String content) {
    return Padding(
      padding: EdgeInsets.only(left: 72.w),
      child: Text(
        content,
        style: TextStyle(fontSize: 32.sp, color: const Color(0xFF333333)),
      ),
    );
  }
}
